package D1;


class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test1 {

    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        System.out.println(s1.toUpperCase());//将小写转为大写
        System.out.println(s2.toLowerCase());//将大写转为小写
    }
    public static void main9(String[] args) {
        int d1 = Integer.parseInt("1234");
        double d2 = Double.parseDouble("23.33");
        System.out.println(d1);
        System.out.println(d2);
    }
    public static void main8(String[] args) {
         String s1 = String.valueOf(1234);
         String s2 = String.valueOf(true);
         String s3 = String.valueOf(new Student("zhangsan",22));
         System.out.println(s1);
         System.out.println(s2);
         System.out.println(s3);
    }
    public static void main7(String[] args) {
        String s1 = new String("aaabbbcccaaabbbccc");
        System.out.println(s1.charAt(3));//b  返回3下标的字符'b'
        System.out.println(s1.indexOf("b"));//3  返回b(可以是字符或数字)第一次出现的下标,没有则返回-1
        System.out.println(s1.indexOf("b",2));//3  返回b(可以是字符或数字)从下标2开始,第一次出现的下标,没有则返回-1
        System.out.println(s1.indexOf("bbb",2));//3

        System.out.println(s1.lastIndexOf("b"));//14  从后往前找,返回b(可以是字符或数字)第一次出现的下标,没有则返回-1
        System.out.println(s1.lastIndexOf("b",10));//5  从10下标开始,从后往前找,返回b(可以是字符或数字)第一次出现的下标,没有则返回-1
        System.out.println(s1.lastIndexOf("bbb",10));//3

    }
    public static void main6(String[] args) {
        String s1 = new String("abcde");
        String s2 = new String("abc");
        String s3 = new String("ABC");
        String s4 = new String("abcde");

        System.out.println(s1.compareToIgnoreCase(s2));//2 前k个字符串相等,返回长度差值2
        System.out.println(s1.compareToIgnoreCase(s3));//2 忽略大小写后,前k个字符串相等,返回长度差值2
        System.out.println(s1.compareToIgnoreCase(s4));//0 相等返回0
    }
    public static void main5(String[] args) {
        String s1 = new String("abcde");
        String s2 = new String("abc");
        String s3 = new String("ABC");
        String s4 = new String("abcde");

        System.out.println(s1.compareTo(s2));//2 前k个字符串相等,返回长度差值2
        System.out.println(s1.compareTo(s3));//32 返回符号差值32
        System.out.println(s1.compareTo(s4));//0 相等返回0
    }
    public static void main3(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = new String("hello");
        String s4 = s1;

    }
    public static void main4(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = new String("hello");
        String s4 = s1;

        System.out.println(s1.compareTo(s2));//-15,返回符号差值
        System.out.println(s1.compareTo(s3));//0,相等
        System.out.println(s1.compareTo(s4));//0,相等
    }
    public static void main2(String[] args) {

        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = new String("hello");
        String s4 = s1;
        System.out.println(s1.equals(s2));//false
        System.out.println(s1.equals(s3));//true
        System.out.println(s1.equals(s4));//true
    }


    public static void main1(String[] args) {
        //基本类型变量，比较变量中存储的值是否相等
        int a = 10;
        int b = 20;
        int c = 10;
        System.out.println(a == c);//true
        System.out.println(b == c);//false

        //引用类型变量，比较两个引用变量引用的是否是同一个对象
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = new String("hello");
        String s4 = s1;
        System.out.println(s1 == s2);//false
        System.out.println(s1 == s3);//false
        System.out.println(s1 == s4);//true
    }
}